package com.qfmy.mystation.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.qfmy.mystation.R;

public class TagListAdapter extends RecyclerView.Adapter<TagListAdapter.MyViewHolder> {
    private String[] tagList;
    private int layout;

    public TagListAdapter(String[] tagList, int layout) {
        this.tagList = tagList;
        this.layout = layout;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.tv_tag.setText(tagList[position]);
    }

    @Override
    public int getItemCount() {
        return tagList == null ? 0 : tagList.length;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private final TextView tv_tag;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_tag = itemView.findViewById(R.id.tv_tag);
        }
    }
}
